package com.group02.community.service.impl;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.group02.community.entity.user.SysUser;
import com.group02.community.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        SysUser sUser = userMapper.selectOne(new QueryWrapper<SysUser>().lambda().eq(SysUser::getUserName, username));
        if (sUser==null){
            throw new UsernameNotFoundException("用户名不存在");
        }
        return new org.springframework.security.core.userdetails.User(username,sUser.getPassword(), AuthorityUtils.commaSeparatedStringToAuthorityList(""));
    }
}
